package com.pzr.soccer.config.redis;

import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisHelper<T> {
    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @Autowired
    Gson gson;

    public  void set(String key,T t){
        String oStr=gson.toJson(t);
         redisTemplate.opsForValue().set(key,oStr);
    }

    public  T get(String key,Class<T> clazz){
        String oStr= (String) redisTemplate.opsForValue().get(key);
        T result=(T) gson.fromJson(oStr,clazz);
        return result;
    }
}
